class Particle {

  float x_loc; 
  float y_loc;


  int mass; ///diameter
  float radius;

  float rotation;
  float velocity;

  boolean alive=true;

  boolean star=false;
  PImage star_image;
  color cc;

 Particle() {
    float offset=0;
    set_mass(1);


    cc =  color(random(230,255),random(240,255),random(230,255));

    x_loc = random(0,width);
    y_loc = random(height-3,height-0);
    rotation = random(0,360);
    star_image = loadImage("data/star.png");
    velocity = .3;
  }


  void set_x() {
    x_loc = x_loc + cos(radians(rotation))*velocity ;
  }
  void set_y() {
    y_loc = y_loc + sin(radians(rotation))*velocity ;
  }


  void math() {
    if(alive) {

      clamp_to_stage();
      clamp_rotation();

      speed();

      set_x();
      set_y();
    }
  }

  ///// never change mass any other way or it will explode in bad ways !
  void set_mass(int mass) {
    this.mass = mass;
    radius = (float)mass/2;
  }


  void speed() {
    if(mass <=4) {
      velocity = .3;
      star=false;
    }

    if ((mass >4) && (mass<10)) {
      velocity = .2;
      star = true;
    }
    else {
      if(mass>10) {
        velocity =.1;
        //space whale = true; its reals
      }
    }
  }

  void render() {
    if(alive) {
      if(star) {
        pushMatrix();
        image(star_image,x_loc,y_loc,mass+1,mass+1);
        popMatrix();
      }
      else {
        fill(cc);
        rect(x_loc,y_loc,mass,mass);
      }
    }
  }

  void set_alive(boolean alive) {
    this.alive = alive;
  }

  boolean get_alive() {
    return alive;
  }

  //// needs to account for objects size
  /// grab the function from the other program that does this the right way
  /* void clamp_to_stage() {
   //if(mass > 5) {
   if(x_loc <0) {
   x_loc = 1;
   
   float hungryRaptor = random(0,180);
   if(hungryRaptor <90) {
   rotation = map(hungryRaptor,0,90,270,360);
   }
   else {
   rotation = map(hungryRaptor,90,180,0,90);
   }
   }
   
   if(x_loc >width) {
   x_loc = width;
   rotation = random(90,270);
   }
   
   if(y_loc <0) {
   y_loc = 1;
   rotation = random(0,180);
   }
   
   if(y_loc >height) {
   y_loc = height-1;
   rotation = random(180,360);
   }
   //  }
   }
   */
  ///erm this is the other function but it was from a really sketchy old sketch but it seems right
  /// I should check it later
  void clamp_to_stage() {
    if(x_loc<0) {
      x_loc =0+velocity;
      rotation = rotation+(180-(rotation*2));
    }
    else {
      if(x_loc>width) {
        x_loc =width-velocity;
        rotation = rotation+(180-(rotation*2));
      }
    }

    if(y_loc<0) {
      y_loc =0+velocity;
      rotation = rotation-(180-(rotation*2));
    }
    else {
      if(y_loc>height) {
        y_loc =height-velocity;
        rotation = rotation-(180-(rotation*2));
      }
    }
  }



  void clamp_rotation() {
    if(rotation > 360) {
      rotation = rotation - 360;
    } 
    if(rotation < 0) {
      rotation = rotation + 360;
    }
  }

  void reset(float x_loc, float y_loc) {
    set_mass(1);
    velocity = .3;
    rotation = random(0,360);
    this.x_loc = x_loc;
    this.y_loc = y_loc;
  }
}

